Problem with UrlDecode

18 views
Skip to first unread message

graphicsxp

unread,
Mar 5, 2009, 5:23:43 AM3/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hello,

I'm passing the following string in my querystring : "test & test £"
and I encode the string in javascript so that the server receives :
test%20%26%20test%20%A3

All is fine but when I use Server.UrlDecode in my server code, the
string is decoded as : "test & test 'square' "

in place of square, it is an actual square shape, like the %A3 bit was
not decoded properly to a £ sign.

What am I doing wrong ?

Thank you

Cerebrus

unread,
Mar 5, 2009, 12:03:19 PM3/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
You haven't explained how you are encoding the URL via Javascript.
Whatever that method is, it appears to be incorrectly encoding the
Pound symbol. The encoded value of the symbol should be "%C2%A3".

I would suggest that you use the encodeURI() built-in function in
Javascript.

graphicsxp

unread,
Mar 5, 2009, 1:02:38 PM3/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Thanks for helping


I am using encodeURI() but at the same time I was using escape(). If I
use encodeURI() alone, then it is converted to %C2%A3 and all is fine.
However if I don't use escape() then all my ampersand (&) are just
discarded.

If I pass 'test & £' in my querystring, when I try to decode that on
the server end, it becomes 'test £'

Maybe it's more a javascript issue and I shouldn't post here but I'm
not sure.....

Cerebrus

unread,
Mar 5, 2009, 1:30:38 PM3/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
It's all right... Javascript has become so deeply integrated with all
web technologies that I hardly notice that this is not a Javascript
Group. So, don't worry, we cater to Javascript as well <fanfare
music> !!!

Instead of using escape() which is not recommended, try using the
encodeURIComponent() method instead which should do the conversion
properly. I haven't tried it, but I think it should be able to handle
the Pound sign.
> > > Thank you- Hide quoted text -
>
> - Show quoted text -

graphicsxp

unread,
Mar 6, 2009, 4:38:43 AM3/6/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
encodeURIComponent was the solution, thank you so much ! :)
Reply all
Reply to author
Forward
0 new messages